package com.icss.ah.salesTopology.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.alibaba.fastjson.JSONArray;
import com.icss.ah.base.action.BaseAction;
import com.icss.ah.login.bean.UserInfoBean;
import com.icss.ah.salesTopology.service.SalesTopologyService;

/**
 * 销售额拓扑控制类
 * @date 2017-8-8
 */
@Controller
@Scope("prototype")
public class SalesTopologyAction extends BaseAction {

	private static final long serialVersionUID = 12342L;
	
	@Autowired
	private SalesTopologyService salesTopologyService;
	
	private String begDate;
	private String endDate;
	
	/**
	 * 数据展示页
	 */
	public String toSalesTopologyPage(){
		return "toSalesTopologyPage";
	}
	
	/**
	 * 品类销售额查询（平台品类）
	 */
	public void queryCategorySales(){
		Map<String, String> map = getParaMap();
		List<Map<String, Object>> list = salesTopologyService.queryCategorySales(map);
		str2Resp(JSONArray.toJSONString(list));
	}
	
	/**
	 * 品牌销售额查询
	 */
	public void queryBrandSales(){
		Map<String, String> map = getParaMap();
		List<Map<String, Object>> list = salesTopologyService.queryBrandSales(map);
		str2Resp(JSONArray.toJSONString(list));
	}
	
	/**
	 * 商品销售额查询
	 */
	public void queryProductSales(){
		Map<String, String> map = getParaMap();
		List<Map<String, Object>> list = salesTopologyService.queryProductSales(map);
		str2Resp(JSONArray.toJSONString(list));
	}
	
	/*
	 * 查询参数 
	 */
	public Map<String, String> getParaMap(){
		String userCode=getUserCodeFromSession();
		UserInfoBean userInfo=getUserInfo(userCode);
		String corpId = userInfo.getCorpId();
		String shopId=userInfo.getShopId();
		Map<String, String> map = new HashMap<String, String>();
		map.put("corpId", corpId);
		map.put("shopId", shopId);
		map.put("begDate", begDate);
		map.put("endDate", endDate);
		map.put("numFlag", "1");
		return map;
	}

	public String getBegDate() {
		return begDate;
	}

	public void setBegDate(String begDate) {
		this.begDate = begDate;
	}

	public String getEndDate() {
		return endDate;
	}

	public void setEndDate(String endDate) {
		this.endDate = endDate;
	}

}
